#include <iostream>
#include <cstring>

using namespace std;

const int N = 70;

int n, sum, length;
int w[N];
bool st[N];

bool dfs(int u, int s, int start) {
    if (u * length == sum) return true;
    if (s == length) return dfs(u + 1, 0, 0);

    for (int i = start; i < n; ++ i) {
        if (s + w[i] > length || st[i]) continue;

        st[i] = true;
        if (dfs(u, s + w[i], i + 1)) return true;
        st[i] = false;

        if (!s || s + w[i] == length) return false;

        int j = i;
        while (j < n && w[j] == w[i]) j ++ ;
        i = j - 1;
    }

    return false;
}

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    while (cin >> n, n) {
        memset(st, 0, sizeof st);

        sum = 0;
        for (int i = 0; i < n; ++ i) {
            scanf("%d", w + i);
            sum += w[i];
        }

        sort(w, w + n, cmp);

        length = w[0];
        while (1) {
            if (sum % length == 0 && dfs(0, 0, 0)) {
                printf("%d\n", length);
                break;
            }
            length ++ ;
        }
    }

    return 0;
}